package qimao.com.edu.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.fasterxml.jackson.databind.ObjectMapper;

import qimao.com.edu.DTO.BookDTO;
import qimao.com.edu.entity.Works;
import qimao.com.edu.service.WorksService;
import qimao.com.edu.service.impl.WorksServiceImpl;


@WebServlet("/BookRed.do")
public class BookRedServlet extends HttpServlet{
	
	ObjectMapper om = new ObjectMapper();
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("application/json;charset=UTF-8");
		
		WorksService ws = new WorksServiceImpl();
		Map<String, Object> responseData = new HashMap<>();
		int workId = Integer.parseInt(request.getParameter("bookId"));
		
		BookDTO bookDTO = ws.selectBookDTO(workId);
		
		responseData.put("success", true);
	    responseData.put("message", "成功");
	    responseData.put("data", bookDTO);
	    System.out.println(bookDTO);
	    response.getWriter().write(om.writeValueAsString(responseData));
	    
	}
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
}
